package com.homework.work03;

/**
 * 插入排序
 */
public class SortDemo3 {
    public static void main(String[] args) {
        //定义数组
        int[] arr = {1,11,9,3,7,5};
        //插入排序
        for(int index = 1;index<arr.length;index++){
            int t = arr[index];
            int leftIndex = index-1;
            while(leftIndex>=0 && arr[leftIndex]>t){
                arr[leftIndex+1] = arr[leftIndex];
                leftIndex--;
            }
            arr[leftIndex+1] = t;
        }
        //打印数组
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
    }
}
